package Presenter;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import Models.MaltInventoryView;

public class MaltInventoryViewPresenter extends AbstractPresenter<MaltInventoryView> {
	final String SINGLEITEM = "maltInventoryView";
	final String MULTIITEM = "maltInventoryViews";
	
	public ArrayList<MaltInventoryView> tryJSONParseArray(String input){
		return super.doJSONParseArray(input, SINGLEITEM, MULTIITEM);
	}
	
	public MaltInventoryView tryJSONParse(String input){
		return super.doJSONParse(input, SINGLEITEM);
	}
	
	public MaltInventoryView createItemFromJSONObject(JSONObject jsonObject){
		MaltInventoryView item = new MaltInventoryView();
		try{
			item.setMaltID(jsonObject.getInt("maltID"));
			item.setMaltName(jsonObject.getString("maltName"));
			item.setMaltOnHand(jsonObject.getDouble("maltOnHand"));
			item.setMaltOnOrder(jsonObject.getDouble("maltOnOrder"));
			item.setMaltSpoken(jsonObject.getDouble("maltSpoken"));
			return item;
		} catch(JSONException ex){
			ex.printStackTrace();
		} catch(Exception ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public JSONObject createJSON(MaltInventoryView item){
		try{
			JSONObject json = new JSONObject();
			json.put("maltID", item.getMaltID());
			json.put("maltName", item.getMaltName());
			json.put("maltOnHand", item.getMaltOnHand());
			json.put("maltOnOrder", item.getMaltOnOrder());
			json.put("maltSpoken", item.getMaltSpoken());
			return json;
		} catch(JSONException ex){
			ex.printStackTrace();
		}
		return null;
	}
	
	public MaltInventoryView getEmptyEntity(){
		MaltInventoryView entity = new MaltInventoryView();
		return entity;
	}
}
